<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<#include "../../common/header.html">

<script type="text/javascript" src="/cloudpay/js/plupload/plupload_1_5_7/plupload/js/plupload.full.js"></script>
<script type="text/javascript" src="/cloudpay/js/plupload/plupload_1_5_7/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/cloudpay/js/plupload/plupload_1_5_7/plupload/js/i18n/zh-CN.js"></script>
<link rel="stylesheet" href="/cloudpay/js/plupload/plupload_1_5_7/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css"></link>

</head>
<body class="hold-transition skin-purple-light sidebar-mini">
	<div class="wrapper">

		<!-- 	顶部和左侧菜单的jsp s -->
		<#include "../../common/menu.html">
		<!-- 	顶部和左侧菜单的jsp e -->

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>上传视频</h1>
			</section>
			<div id="uploader" style="width: 500px;">您的浏览器没有安装Flash插件，或不支持HTML5！</div>					
		</div>

	</div>
	<!-- ./wrapper -->
</body>
<script>
$(function() {
	$("#uploader").pluploadQueue({
		runtimes : 'html5,flash',//设置运行环境，会按设置的顺序，可以选择的值有html5,gears,flash,silverlight,browserplus,html4
		flash_swf_url : '/cloudpay/js/plupload/plupload_1_5_7/plupload/js/plupload.flash.swf',// Flash环境路径设置
		silverlight_xap_url : '/cloudpay/js/plupload/jslib/plupload_1_5_7/plupload/js/plupload.silverlight.xap',//silverlight环境路径设置
		url : '/cloudpay/system/aliyunMultipartUpload',//上传文件路径
		max_file_size : '3gb',//100b, 10kb, 10mb, 1gb
		chunk_size : '500kb',//分块大小，小于这个大小的不分块
		unique_names : true,//生成唯一文件名
		
		// 如果可能的话，压缩图片大小
		// resize : { width : 320, height : 240, quality : 90 },
		// 指定要浏览的文件类型
		filters : [ {
			title : 'Image files',
			extensions : 'jpg,gif,png'
		}, {
			title : 'Zip files',
			extensions : 'zip,7z'
		},
		 {
			title : 'shipin files',
			extensions : 'mp4,avi'
		}],
		multipart_params : {
			"uploadId":"",
			"key":"",
			"bucketName":""
		},
		init : {
			FileUploaded : function(up, file, info) {//文件上传完毕触发
				
				console.log("FileUploaded");
				up.settings.multipart_params.uploadId = ""
				up.settings.multipart_params.key = "";
				up.settings.multipart_params.bucketName = "";
				
				 $.ajax({
					 url : '/traffic/video/saveVideoUrl',
					 type : "POST",
					 async:false,
					 dataType : "json",
					 data : {key:$.parseJSON(info.response).key,videoId:GetQueryString("videoId")},
					 success : function(result) {	
						 //如果返回成功
						 if(result.result_code == successRespCode) {
							 alert("上传成功");
						 } else {
						     alert("上传你失败，请重试");
						 }
					 }
				 });
				
				/* console.info(up);
				console.info(file);
				console.info(info);
				var response = $.parseJSON(info.response);
				if (response.status) {
					$('#f1').append('<input type="text" name="fileUrl" value="'+response.fileUrl+'"/>');
					$('#f1').append('<input type="text" name="fileName" value="'+file.name+'"/><br/>');
				} */
			},
			ChunkUploaded : function(up, file, info) {
				
				console.log("ChunkUploaded");
				
				var response = $.parseJSON(info.response);
				up.settings.multipart_params.uploadId = response.uploadId;
				up.settings.multipart_params.key = response.key;
				up.settings.multipart_params.bucketName = response.bucketName;
				
				/* console.log(up);
				var oriOption = up.settings.multipart_params;
				console.log(oriOption.test);
				oriOption.test = "2222222222";
				console.log(oriOption.test); */
			},
			UploadComplete : function (up,filters) {
				console.log(filters);
			},				
			FilesAdded : function(up, file){
				//限制只上传一个文件 ===start
                if(up.files.length>1) { // 最多上传1张图
                	up.splice(1, up.files.length-1);
                }
				//限制只上传一个文件====end
            },				
			Error : function(up,errorObj) {
				alert("上传失败");
			}
		}
	});

});

</script>
</html>